package com_3;

import java.util.ArrayList;
import java.util.function.Predicate;

/*
通过predicate函数接口将数组中符合条件的数据存入到集合中
 */
public class TestDemo4 {
    public static void main(String[] args) {
 String[]arr={"诸葛亮,45","曹操,23","周瑜,36"};

   ArrayList<String> list=getArray(arr,s -> s.split(",")[0].length()>1,s -> Integer.parseInt(s.split(",")[1])>25);
        System.out.println(list);
    }
    public  static ArrayList<String> getArray(String[]arr, Predicate<String> pre1,Predicate<String > pre2){
        ArrayList<String> list=new ArrayList<>();
        for (String s : arr) {
            if(pre1.and(pre2).test(s)){
                list.add(s);
            }
        }
        return list;
    }
}
